]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
shew: Use Xlib to set transient hint
authorFlorian Müllner <fmuellner@gnome.org>
Wed, 15 Apr 2020 18:27:15 +0000 (20:27 +0200)
committerMarge Bot <marge-bot@gnome.org>
Thu, 14 Jan 2021 13:03:21 +0000 (13:03 +0000)
The GDK API for setting the hint has been removed in GDK4, so prepare
for a port by using the underlying Xlib API directly.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1495>

subprojects/shew/meson.build
subprojects/shew/src/meson.build
subprojects/shew/src/shew-external-window-x11.c

index 3accbe67af7d9dfe71f6a906f37a5c4c0308694b..c19653421fe7f6451220e7d4770248751e850fe7 100644 (file)
@@ -23,5 +23,6 @@ girdir = join_paths(pkgdatadir, 'gir-1.0')
 typelibdir = join_paths(pkglibdir, 'girepository-1.0')
 
 gtk_dep = dependency('gtk+-3.0')
+x11_dep = dependency('x11', required: false)
 
 subdir('src')
index c3b1a6b796f08abca6d70d0a00b7d537a8a8b39b..f3bff582710e312efcae200ad4586c12405db5be 100644 (file)
@@ -12,7 +12,7 @@ shew_sources = [
 
 libshew = library(full_name,
   sources: shew_sources,
-  dependencies: [gtk_dep],
+  dependencies: [gtk_dep, x11_dep],
   install_dir: pkglibdir,
   install: true,
 )
index 5c4c8e69e82562196c203e757119633ec975b9d9..0504a30f7aa276e0e5f4c53e66f0dfaa86a67eb0 100644 (file)
@@ -22,6 +22,7 @@
 #include <gdk/gdk.h>
 #ifdef GDK_WINDOWING_X11
 #include <gdk/gdkx.h>
+#include <X11/Xlib.h>
 #endif
 #include <stdlib.h>
 
@@ -33,7 +34,7 @@ struct _ShewExternalWindowX11
 {
   ShewExternalWindow parent;
 
-  GdkWindow *foreign_gdk_window;
+  int foreign_xid;
 };
 
 G_DEFINE_TYPE (ShewExternalWindowX11, shew_external_window_x11,
@@ -54,13 +55,29 @@ get_x11_display (void)
   return x11_display;
 }
 
+static gboolean
+check_foreign_xid (GdkDisplay *display,
+                   int         xid)
+{
+  gboolean result = FALSE;
+#ifdef GDK_WINDOWING_X11
+  XWindowAttributes attrs;
+
+  gdk_x11_display_error_trap_push (display);
+  result = XGetWindowAttributes (GDK_DISPLAY_XDISPLAY (display), xid, &attrs);
+  if (gdk_x11_display_error_trap_pop (display))
+    return FALSE;
+
+#endif
+  return result;
+}
+
 ShewExternalWindowX11 *
 shew_external_window_x11_new (const char *handle_str)
 {
   ShewExternalWindowX11 *external_window_x11;
   GdkDisplay *display;
   int xid;
-  GdkWindow *foreign_gdk_window = NULL;
 
   display = get_x11_display ();
   if (!display)
@@ -77,20 +94,16 @@ shew_external_window_x11_new (const char *handle_str)
       return NULL;
     }
 
-#ifdef GDK_WINDOWING_X11
-  foreign_gdk_window = gdk_x11_window_foreign_new_for_display (display, xid);
-#endif
-
-  if (!foreign_gdk_window)
+  if (!check_foreign_xid (display, xid))
     {
-      g_warning ("Failed to create foreign window for XID %d", xid);
+      g_warning ("Failed to find foreign window for XID %d", xid);
       return NULL;
     }
 
   external_window_x11 = g_object_new (SHEW_TYPE_EXTERNAL_WINDOW_X11,
                                       "display", display,
                                       NULL);
-  external_window_x11->foreign_gdk_window = foreign_gdk_window;
+  external_window_x11->foreign_xid = xid;
 
   return external_window_x11;
 }
@@ -102,18 +115,11 @@ shew_external_window_x11_set_parent_of (ShewExternalWindow *external_window,
   ShewExternalWindowX11 *external_window_x11 =
     SHEW_EXTERNAL_WINDOW_X11 (external_window);
 
-  gdk_window_set_transient_for (child_window,
-                                external_window_x11->foreign_gdk_window);
-}
-
-static void
-shew_external_window_x11_dispose (GObject *object)
-{
-  ShewExternalWindowX11 *external_window_x11 = SHEW_EXTERNAL_WINDOW_X11 (object);
-
-  g_clear_object (&external_window_x11->foreign_gdk_window);
-
-  G_OBJECT_CLASS (shew_external_window_x11_parent_class)->dispose (object);
+#ifdef GDK_WINDOWING_X11
+  XSetTransientForHint (GDK_WINDOW_XDISPLAY (child_window),
+                        GDK_WINDOW_XID (child_window),
+                        external_window_x11->foreign_xid);
+#endif
 }
 
 static void
@@ -124,10 +130,7 @@ shew_external_window_x11_init (ShewExternalWindowX11 *external_window_x11)
 static void
 shew_external_window_x11_class_init (ShewExternalWindowX11Class *klass)
 {
-  GObjectClass *object_class = G_OBJECT_CLASS (klass);
   ShewExternalWindowClass *external_window_class = SHEW_EXTERNAL_WINDOW_CLASS (klass);
 
-  object_class->dispose = shew_external_window_x11_dispose;
-
   external_window_class->set_parent_of = shew_external_window_x11_set_parent_of;
 }